<template>
  <custom-tree ref="tree" :data="data" @refresh="loadTree" @node-click="handleNodeClick" />
</template>
<script>
  import CustomTree from '@/pages/components/customTree'
  import * as service from '@/api/crud.base';
  export default {
    components:{
      CustomTree
    },
    data() {
      return {
        data: [],
      }
    },
    methods: {
      handleNodeClick(data) {
        this.$emit('node-click', data)
      },
      loadTree() {
        service.list('/orgs').then(res => {
          this.data = res;
        });
      },
      getNameById(id){
        let name = ''
        for (let record of this.data) {
          if (record.id == id) {
            name = record.name;
            break;
          }
        }
        return name;
      }
    },
    mounted() {
      this.loadTree();
    }
  }
</script>
